package org.jeik.data.models;

import java.util.ArrayList;
import java.util.List;

import org.jeik.data.services.ServiceBase.Tables;

/**
 * 
 * @author AAsha
 *
 */
@SuppressWarnings("serial")
public class ServiceParent implements Model,Comparable<ServiceParent>{
	
	private Long id;
	private String serviceTitle;
	private Long type;
	private List<Service> requests = new ArrayList<Service>();
	private Integer index;
	
	public ServiceParent() {
	}
	
	public String getServiceTitle() {
		return serviceTitle;
	}
	public void setServiceTitle(String serviceTitle) {
		this.serviceTitle = serviceTitle;
	}
	public List<Service> getRequests() {
		return requests;
	}
	public void setRequests(List<Service> requests) {
		this.requests = requests;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}
	
	public Long getType() {
		return type;
	}
	
	public void setType(Long type) {
		this.type = type;
	}

	@Override
	public String getTableName() {
		return Tables.service_parents.name();
	}

	@Override
	public List<String> getFields() {
		return null;
	}

	/**
	 * @return the index
	 */
	public Integer getIndex() {
		return index;
	}

	/**
	 * @param index the index to set
	 */
	public void setIndex(Integer index) {
		this.index = index;
	}
	
	/**
	 * @param index the index to set
	 */
	public void setIndex(Object index) {
		if(index == null){
			this.index = 0;
		}
		this.index = Integer.valueOf(index.toString());
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ServiceParent other = (ServiceParent) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

	@Override
	public int compareTo(ServiceParent o) {
		return index < o.index ? -1 : index > o.index ? 1 : 0;
	}
	
}
